package com.qidian.mes.defect.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.mapper.DetectionItemMapper;
import com.qidian.mes.defect.service.DetectionItemService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.pojo.DetectName;
import com.qidianit.mes.pojo.Detection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-22 22:58
 */
@Service
public class DetectionItemServiceImpl implements DetectionItemService {
    @Autowired
    private DetectionItemMapper detectionItemMapper;


    @Override
    public MESResult list(String detectionName, String detectionType, String detectionTool, String detectionMethod, String standardValue, String unit, Long errorCap, Long errorLow, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<DetectName> detectNames = detectionItemMapper.selectList(detectionName,detectionType,detectionTool,detectionMethod,standardValue,unit,errorCap,errorLow);
        PageInfo<DetectName> pageInfo = new PageInfo<>(detectNames);
        // 将pageInfo对象设置到MESResult中
        return MESResult.success(pageInfo);

    }

    @Override
    public MESResult save(DetectName detectName) {
        return detectionItemMapper.insert(detectName) == 1?MESResult.success():MESResult.error();
    }

    @Override
    public MESResult update(DetectName detectName) {
        return MESResult.success(200,"ok",detectionItemMapper.update(detectName));

    }

    @Override
    public MESResult selectById(Long detectionId) {
        return MESResult.success(detectionItemMapper.selectById(detectionId));

    }


}
